package com.example.itshome.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import com.bumptech.glide.Glide;
import com.example.itshome.R;

import java.util.ArrayList;
import java.util.List;

public class CircleImageAdapter extends PagerAdapter {

    private final List<View> images;

    public CircleImageAdapter(List<String> images, LayoutInflater inflater, Context context){
        this.images=new ArrayList<>();
        for (String image:images){
            View view=inflater.inflate(R.layout.fragment_circle_particular_image_item,null);
            ImageView imageView= view.findViewById(R.id.imv_circle_particular);
            if(context!=null){
                Glide.with(context).load(image).placeholder(R.drawable.sample_picture).into(imageView);
            }
            this.images.add(view);
        }
    }

    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View v=images.get(position);
        container.addView(v);
        return v;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView(images.get(position));
    }

}
